package com.tengju.bff.infrastructure.persistence.redis;

import com.tengju.bff.domain.service.WithdrawService;
import com.tengju.bff.domain.shared.UserIdCode;
import com.tengju.bff.infrastructure.persistence.redis.dataobject.RedisKeyObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

import static com.tengju.bff.infrastructure.persistence.redis.dataobject.RedisKeyPrefix.*;

/**
 * @author wuziyang
 */
@Repository
public class WithdrawCacheRepository implements WithdrawService {

    @Autowired
    private RedisService redisService;


    /**
     * 存储token
     */
    @Override
    public boolean isPersonalAuthClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_LETAX_SERVICE_PERSONAL_AUTH, idCode.toString());
        return redisService.getString(key) != null;
    }

    @Override
    public void personalAuthClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_LETAX_SERVICE_PERSONAL_AUTH, idCode.toString());
        redisService.setValue(key, 1, 5, TimeUnit.SECONDS);
    }

    @Override
    public boolean isRegisteredCheckClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_LETAX_REGISTERED_INFO_CHECK, idCode.toString());
        return redisService.getString(key) != null;
    }

    @Override
    public void registeredCheckClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_LETAX_REGISTERED_INFO_CHECK, idCode.toString());
        redisService.setValue(key, 1, 10, TimeUnit.SECONDS);
    }

    @Override
    public boolean isAddRegisteredCheckClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_ADD_LETAX_REGISTERED_INFO_CHECK, idCode.toString());
        return redisService.getString(key) != null;
    }

    @Override
    public void addRegisteredCheckClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_SERVICE_ADD_LETAX_REGISTERED_INFO_CHECK, idCode.toString());
        redisService.setValue(key, 1, 10, TimeUnit.SECONDS);
    }

    @Override
    public boolean isUpdateWithdrawalLogClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_UPDATE_WITHDRAWAL_LOG, idCode.toString());
        return redisService.getString(key) != null;
    }

    @Override
    public void updateWithdrawalLogClick(UserIdCode idCode) {
        RedisKeyObject key = new RedisKeyObject(WEB_UPDATE_WITHDRAWAL_LOG, idCode.toString());
        redisService.setValue(key, 1, 10, TimeUnit.SECONDS);
    }
}
